<template>
  <div class="editBox">
    <el-button size="mini" @click="handleEdit()">编辑</el-button>
    <el-dialog :show-close="false" destroy-on-close :modal-append-to-body="false" title="提示" :visible="dialogVisible" width="30%">
      <el-form label-position="right" label-width="80px" :model="formLabelAlign">
        <el-form-item label="学号">
          <el-input v-model="formLabelAlign.stuNo"></el-input>
        </el-form-item>
        <el-form-item label="学校">
          <el-select v-model="formLabelAlign.schoolId" placeholder="请选择">
            <el-option v-for=" item,index in $store.state.school.profile" :key="item.schoolId" :label="item.schoolName" :value="item.schoolId"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="姓名">
          <el-input v-model="formLabelAlign.username"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-input v-model="formLabelAlign.gender"></el-input>
        </el-form-item>
        <el-form-item label="类型">
          <el-select v-model="formLabelAlign.userType" placeholder="请选择">
            <el-option v-for=" item,index in $store.state.user.roles" :key="index" :label="item.name" :value="item.userType"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="formLabelAlign.email"></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="formLabelAlign.phone"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { register } from '@/api/user'
export default {
  props: {
    info: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      dialogVisible: false,
      formLabelAlign: {
        schoolId: '',
        stuNo: '',
        username: '',
        phone: '',
        gender: '',
        userType: '',
        email: '',
        userId: ''
      }
    }
  },
  mounted() {
    const { schoolId, stuNo, username, phone, gender, userType, email, userId } = this.info
    const data = { schoolId, stuNo, username, phone, gender, userType, email, userId }
    this.formLabelAlign = data
  },
  methods: {
    handleEdit() {
      this.dialogVisible = true
    },
    submit() {
      this.dialogVisible = false
      this.registerFn()
    },
    registerFn() {
      register(this.formLabelAlign).then(res => {
        this.$message({
          type: 'success',
          message: res.msg
        })
        this.$emit('editeChange')
      })
    }
  }
}
</script>

<style lang="less" scoped>
.editBox {
  padding-right: 10px;
}
</style>